package com.mogujie.tt.ui.activity;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.mogujie.tt.DB.sp.LoginSp;
import com.mogujie.tt.DB.sp.RegisterSp;
import com.mogujie.tt.DB.sp.SystemConfigSp;
import com.mogujie.tt.R;
import com.mogujie.tt.config.IntentConstant;
import com.mogujie.tt.config.RegisterConstant;
import com.mogujie.tt.config.UrlConstant;
import com.mogujie.tt.imservice.event.RegisterEvent;
import com.mogujie.tt.imservice.manager.IMRegisterManager;
import com.mogujie.tt.ui.widget.QuanzQzBimp;
import com.mogujie.tt.utils.FileUtil;
import com.mogujie.tt.utils.HttpUtilsApache;
import com.mogujie.tt.utils.IMUIHelper;
import com.mogujie.tt.imservice.event.LoginEvent;
import com.mogujie.tt.imservice.event.SocketEvent;
import com.mogujie.tt.imservice.manager.IMLoginManager;
import com.mogujie.tt.imservice.service.IMService;
import com.mogujie.tt.ui.base.TTBaseActivity;
import com.mogujie.tt.imservice.support.IMServiceConnector;
import com.mogujie.tt.utils.JsonUtil;
import com.mogujie.tt.utils.Logger;
import com.mogujie.tt.utils.MoGuHttpClient;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;

import de.greenrobot.event.EventBus;


/**
 * @YM 1. 链接成功之后，直接判断是否loginSp是否可以直接登陆
 * true: 1.可以登陆，从DB中获取历史的状态
 * 2.建立长连接，请求最新的数据状态 【网络断开没有这个状态】
 * 3.完成
 * <p/>
 * false:1. 不能直接登陆，跳转到登陆页面
 * 2. 请求消息服务器地址，链接，验证，触发loginSuccess
 * 3. 保存登陆状态
 */
public class LoginActivity extends TTBaseActivity {

    private Logger logger = Logger.getLogger(LoginActivity.class);//打印调试信息的封装
    private Handler uiHandler = new Handler();
    private EditText mNameView;
    private EditText mPasswordView;
    private View loginPage;
   // private View splashPage;
    private View mLoginStatusView;
 //   private TextView mSwitchLoginServer;
    private InputMethodManager intputManager;


    private IMService imService;
    private boolean autoLogin = true;
    private boolean loginSuccess = false;

    private IMServiceConnector imServiceConnector = new IMServiceConnector() {//绑定IMService服务
        @Override
        public void onServiceDisconnected() {
        }

        @Override
        public void onIMServiceConnected() {
            logger.d("login#onIMServiceConnected");
            Log.d("onIMServiceConnected","login#onIMServiceConnected");
            imService = imServiceConnector.getIMService();
            try {
                do {
                    if (imService == null) {
                        //后台服务启动链接失败
                  //      Log.v("","imService = "+imService);
                        break;
                    }
                    IMLoginManager loginManager = imService.getLoginManager();
                    LoginSp loginSp = imService.getLoginSp();
                    if (loginManager == null || loginSp == null) {
                        // 无法获取登陆控制器
                   //     Log.v(""," loginManager loginSp = "+loginSp);
                        break;
                    }

                    LoginSp.SpLoginIdentity loginIdentity = loginSp.getLoginIdentity();
                    if (loginIdentity == null) {
                        // 之前没有保存任何登陆相关的，跳转到登陆页面
                   //     Log.v("","loginIdentity = "+loginIdentity);
                        break;
                    }

                    mNameView.setText(loginIdentity.getLoginName());
                    if (TextUtils.isEmpty(loginIdentity.getPwd())) {
                        // 密码为空，可能是loginOut
                        break;
                    }
                    mPasswordView.setText(loginIdentity.getPwd());

                    if (autoLogin == false) {
                        break;
                    }

                    handleGotLoginIdentity(loginIdentity);
                    return;
                } while (false);

                // 异常分支都会执行这个
                handleNoLoginIdentity();
            } catch (Exception e) {
                // 任何未知的异常
                logger.w("loadIdentity failed");
                handleNoLoginIdentity();
            }
        }
    };


    /**
     * 跳转到登陆的页面
     */
    private void handleNoLoginIdentity() {
        logger.i("login#handleNoLoginIdentity");

        uiHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                showLoginPage();
            }
        }, 1000);
    }

    /**
     * 自动登陆
     */
    private void handleGotLoginIdentity(final LoginSp.SpLoginIdentity loginIdentity) {
        logger.i("login#handleGotLoginIdentity");

        uiHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                logger.d("login#start auto login");
                if (imService == null || imService.getLoginManager() == null) {
                    Toast.makeText(LoginActivity.this, getString(R.string.login_failed), Toast.LENGTH_SHORT).show();
                    showLoginPage();
                }
                imService.getLoginManager().login(loginIdentity);//自动登录
            }
        }, 500);
    }


    private void showLoginPage() {
   //     Log.v("","showLoginPage------------------");
     //   splashPage.setVisibility(View.GONE);
        loginPage.setVisibility(View.VISIBLE);//设置登录页面显示
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        intputManager = (InputMethodManager) getSystemService(this.INPUT_METHOD_SERVICE);//得到输入法管理
        logger.d("login#onCreate");

        RegisterSp.instance().init(getApplicationContext());//初始化配置文件
        SystemConfigSp.instance().init(getApplicationContext());//初始化配置文件
        if (TextUtils.isEmpty(SystemConfigSp.instance().getStrConfig(SystemConfigSp.SysCfgDimension.LOGINSERVER))) {  //如果配置文件里面的服务器地址空，就会为其配置
            Log.v("LoginActivity","meg_address = "+SystemConfigSp.instance().getStrConfig(SystemConfigSp.SysCfgDimension.LOGINSERVER));
            SystemConfigSp.instance().setStrConfig(SystemConfigSp.SysCfgDimension.LOGINSERVER, UrlConstant.ACCESS_MSG_ADDRESS);
        }

        imServiceConnector.connect(LoginActivity.this);//绑定服务
        EventBus.getDefault().register(this);//注册事件

        setContentView(R.layout.tt_activity_login);//设置登录界面
      /*  mSwitchLoginServer = (TextView)findViewById(R.id.sign_switch_login_server);//切换服务器
        mSwitchLoginServer.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(LoginActivity.this, android.R.style.Theme_Holo_Light_Dialog));
                LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View dialog_view = inflater.inflate(R.layout.tt_custom_dialog, null);
                final EditText editText = (EditText)dialog_view.findViewById(R.id.dialog_edit_content);
                editText.setText(SystemConfigSp.instance().getStrConfig(SystemConfigSp.SysCfgDimension.LOGINSERVER));
                TextView textText = (TextView)dialog_view.findViewById(R.id.dialog_title);
                textText.setText(R.string.switch_login_server_title);
                builder.setView(dialog_view);
                builder.setPositiveButton(getString(R.string.tt_ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        if(!TextUtils.isEmpty(editText.getText().toString().trim()))
                        {
                            SystemConfigSp.instance().setStrConfig(SystemConfigSp.SysCfgDimension.LOGINSERVER,editText.getText().toString().trim());
                            dialog.dismiss();
                        }
                    }
                });
                builder.setNegativeButton(getString(R.string.tt_cancel), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                });
                builder.show();
            }
        });
*/

        mNameView = (EditText) findViewById(R.id.name);//用户名
        mNameView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View arg0, boolean arg1) {
                // TODO Auto-generated method stub
                //获取触发事件的EditText
                EditText clickEditText = (EditText) arg0;
                //如果失去焦点
                if (arg1 == false) {
                    //获取当前文本
                //    String text = clickEditText.getText().toString().trim();
                    //如果的确人为输入过内容
                   // if (text.length() > 0) {
                      //  clickEditText.setText(text);
                        findViewById(R.id.subscriber_line).setBackgroundColor(Color.rgb(211,211,211));//灰色
                  //  }
                }
                //如果获得焦点
                else {
                    //如果处于未编辑状态，则清空
                   // clickEditText.setText("");
                    findViewById(R.id.subscriber_line).setBackgroundColor(Color.rgb(3,192,43));//青色
                }
            }
        });

        mPasswordView = (EditText) findViewById(R.id.password);//密码
        mPasswordView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View arg0, boolean arg1) {
                // TODO Auto-generated method stub
                //获取触发事件的EditText
                EditText clickEditText = (EditText) arg0;
                //如果失去焦点
                if (arg1 == false) {
                    //获取当前文本
                   // String text = clickEditText.getText().toString().trim();
                    //如果的确人为输入过内容
                  //  if (text.length() > 0) {
                        //  clickEditText.setText(text);
                        findViewById(R.id.password_line).setBackgroundColor(Color.rgb(211,211,211));//灰色
                  //  }
                }
                //如果获得焦点
                else {
                    //如果处于未编辑状态，则清空
                    // clickEditText.setText("");
                    findViewById(R.id.password_line).setBackgroundColor(Color.rgb(3,192,43));//青色
                }
            }
        });
        mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {

                if (id == R.id.login || id == EditorInfo.IME_NULL) {//输入密码
                    attemptLogin();
                    return true;
                }
                return false;
            }
        });
        mLoginStatusView = findViewById(R.id.login_status);//得到水平布局
        //得到按键登录
        findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                intputManager.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);//隐藏软键盘
                attemptLogin();
            }
        });
        //注册按钮
        findViewById(R.id.sign_register_button).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                intputManager.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);//隐藏软键盘
                onSignupPage();
            }
        });
        //忘记密码
        findViewById(R.id.sign_forgot_password_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intputManager.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);//隐藏软键盘
                onForgotPasswordPage();
            }
        });
        initAutoLogin();
    }

    /**
     * 初始化自动登录
     */
    private void initAutoLogin() {
        logger.i("login#initAutoLogin");

      //  splashPage = findViewById(R.id.splash_page);//一开机就是一张图片
        loginPage = findViewById(R.id.login_page);//登录页面
        autoLogin = shouldAutoLogin();//判断显示哪个页面
      //  splashPage.setVisibility(autoLogin ? View.VISIBLE : View.GONE);//如果为true 显示
        loginPage.setVisibility(autoLogin ? View.GONE : View.VISIBLE);

        loginPage.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (mPasswordView != null) {
                    intputManager.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);
                }

                if (mNameView != null) {
                    intputManager.hideSoftInputFromWindow(mNameView.getWindowToken(), 0);
                }

                return false;
            }
        });

        if (autoLogin) { //为true 开始做动作
            Animation splashAnimation = AnimationUtils.loadAnimation(this, R.anim.login_splash);//从不透明到透明
            if (splashAnimation == null) {
                logger.e("login#loadAnimation login_splash failed");
                return;
            }

        //    splashPage.startAnimation(splashAnimation);//开始动作
        }
    }

    // 主动退出的时候， 这个地方会有值,更具pwd来判断
    private boolean shouldAutoLogin() {
        Intent intent = getIntent();//为空就是第一次登录，或者登录退出
        if (intent != null) {
            boolean notAutoLogin = intent.getBooleanExtra(IntentConstant.KEY_LOGIN_NOT_AUTO, false);
            logger.d("login#notAutoLogin:%s", notAutoLogin);
            if (notAutoLogin) {
                return false;
            }
        }
        return true;
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

        imServiceConnector.disconnect(LoginActivity.this);
        EventBus.getDefault().unregister(this);//卸载注册事件
       // splashPage = null;
        loginPage = null;
    }


    /**
     * 尝试登录 点击登录
     */
    public void attemptLogin() {
        String loginName = mNameView.getText().toString();//得到用户
        String mPassword = mPasswordView.getText().toString();//得到密码
        boolean cancel = false;
        View focusView = null;

        if (TextUtils.isEmpty(mPassword)) {
            Toast.makeText(this, getString(R.string.error_pwd_required), Toast.LENGTH_SHORT).show();
            focusView = mPasswordView;
            cancel = true;
        }

        if (TextUtils.isEmpty(loginName)) {
            Toast.makeText(this, getString(R.string.error_name_required), Toast.LENGTH_SHORT).show();
            focusView = mNameView;
            cancel = true;
        }

        if (cancel) {
            focusView.requestFocus();//请求焦点
        } else {
            showProgress(true);//显示进度条
            if (imService != null) {
//				boolean userNameChanged = true;
//				boolean pwdChanged = true;
                loginName = loginName.trim();
                mPassword = mPassword.trim();
                imService.getLoginManager().login(loginName, mPassword);//开始登录.....
            }
        }
    }

    private void showProgress(final boolean show) {
        if (show) {
            mLoginStatusView.setVisibility(View.VISIBLE);
        } else {
            mLoginStatusView.setVisibility(View.GONE);
        }
    }

    // 为什么会有两个这个
    // 可能是 兼容性的问题 导致两种方法onBackPressed
    @Override
    public void onBackPressed() {
        logger.d("login#onBackPressed");
        //imLoginMgr.cancel();
        // TODO Auto-generated method stub
        super.onBackPressed();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
//            LoginActivity.this.finish();
//            return true;
//        }
        return super.onKeyDown(keyCode, event);
    }


    @Override
    protected void onStop() {
        super.onStop();
    }

    /**
     * ----------------------------event 事件驱动----------------------------
     */
    public void onEventMainThread(LoginEvent event) {
        switch (event) {
            case LOCAL_LOGIN_SUCCESS:
            case LOGIN_OK:
                onLoginSuccess();
                break;
            case LOGIN_AUTH_FAILED:
            case LOGIN_INNER_FAILED:
                if (!loginSuccess)
                    onLoginFailure(event);
                break;
        }
    }


    public void onEventMainThread(SocketEvent event) {
        switch (event) {
            case CONNECT_MSG_SERVER_FAILED:
            case REQ_MSG_SERVER_ADDRS_FAILED:
                if (!loginSuccess)
                    onSocketFailure(event);
                break;
        }
    }

    /**
     * 进入注册页面
     */
    private  void onSignupPage(){
        Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
        intent.putExtra("signUpPage",true);
        startActivity(intent);
    }

    /**
     * 进入忘记密码页面
     */
    private void onForgotPasswordPage(){
        Intent intent = new Intent(LoginActivity.this, ForgotPasswordActivity.class);
        startActivity(intent);
    }
    /**
     * 登录成功
     */
    private void onLoginSuccess() {
        logger.i("login#onLoginSuccess");
        loginSuccess = true;
        //创建文件
     /*   String filename = String.valueOf(IMLoginManager.instance().getLoginId())+ ".txt";
        String filePath = RegisterConstant.APP_FILE_PATH +filename;

        //    Log.v("IMLoginManager","filePath = "+filePath);
        if(FileUtil.isFileExist(filePath)){// 存在

        }else{//不存在
            //      Log.v("IMLoginManager","filePath = "+filePath);
            File file =new File(filePath);
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        RegisterConstant.FILE_PATH = filePath;*/
        //请求服务器数据
        new RequestUserDetailedTask(this).executeOnExecutor(Executors.newCachedThreadPool());
        Log.i("login#", "onLoginSuccess");
        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
        startActivity(intent);
        LoginActivity.this.finish();
    }

    /**
     * 登录失败
     * @param event
     */
    private void onLoginFailure(LoginEvent event) {
        logger.e("login#onLoginError -> errorCode:%s", event.name());
        showLoginPage();
        String errorTip = getString(IMUIHelper.getLoginErrorTip(event));
        logger.d("login#errorTip:%s", errorTip);
        mLoginStatusView.setVisibility(View.GONE);
        Toast.makeText(this, errorTip, Toast.LENGTH_SHORT).show();
    }

    /**
     * 连接失败
     * @param event
     */
    private void onSocketFailure(SocketEvent event) {
        logger.e("login#onLoginError -> errorCode:%s,", event.name());
        showLoginPage();
        String errorTip = getString(IMUIHelper.getSocketErrorTip(event));
        logger.d("login#errorTip:%s", errorTip);
        mLoginStatusView.setVisibility(View.GONE);
        Toast.makeText(this, errorTip, Toast.LENGTH_SHORT).show();
    }


    /**
     * 请求用户详细信息
     */
    private class RequestUserDetailedTask extends AsyncTask<Void,Void,String> {

        Context context;
        JSONObject request;
        JSONObject rtjson;//json对象
        String newMessageInfo = "";
        ProgressDialog mProgressDialog;
        String detailedHeadPortrait;//头像
        String detailedNickName;//昵称
        int detailedSex;//性别
        String detailedMobilePhone;//手机
        String detailedEmail;
        String detailedSign;

        public RequestUserDetailedTask(Context context) {
            this.context =context;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
//            mProgressDialog =new ProgressDialog(context);
//            mProgressDialog.setMessage("正在请求同步服务器数据...");
//            mProgressDialog.setCanceledOnTouchOutside(false);
//            mProgressDialog.show();
        }
        @Override
        protected String doInBackground(Void... params) {
             try{
                 Map<String,Object> parms = new HashMap<String, Object>();
                 parms.put("id", LoginSp.instance().getLoginIdentity().getLoginId());//得到登录的ID
                 //   Log.v("1111111111","LoginSp.instance().getLoginIdentity().getLoginId() = "+LoginSp.instance().getLoginIdentity().getLoginId());
                 request = new JSONObject();//新建json格式
                 request = JsonUtil.jsonRequest(RegisterConstant.SERVER_NAME, RegisterConstant.REQUEST_USER_DETAILED, parms);
                 String jsonstr = HttpUtilsApache.usHttpPostJson(RegisterConstant.SERVER_PATH, request);
                 JsonUtil jsonUtil=new JsonUtil();//建立json验证
                 if(jsonstr.length()>3){
                     rtjson=jsonUtil.getOutputJson(jsonstr);
                     Log.v("", "rtjson = " + rtjson);
                 }else{
                     newMessageInfo=HttpUtilsApache.errorMsg(jsonstr);//打印出错信息
                 }
             }catch (Exception e) {

             }


            return null;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);

            if("".equals(newMessageInfo) || newMessageInfo==null)
            {
                if(rtjson!=null && !"".equals(rtjson)){

                    try {
                        String responseCode=rtjson.getString("response_code").toString();
                        if("1".equals(responseCode)) {
                            JSONObject getJsonContext1 = rtjson.getJSONObject("content");
                            JSONArray getJsonUser = getJsonContext1.getJSONArray("user");
                            JSONObject getJsonContext =getJsonUser.getJSONObject(0);

                            detailedNickName = getJsonContext.getString("nick").toString();
                            detailedSex = getJsonContext.getInt("sex");
                            detailedMobilePhone = getJsonContext.getString("phone").toString();
                            detailedEmail = getJsonContext.getString("email").toString();
                            detailedHeadPortrait =getJsonContext.getString("avatar").toString();//得到头像
                            detailedSign = getJsonContext.getString("signInfo").toString();//得到个性签名
                            if(detailedNickName.toString().trim().length() == 0){
                                detailedNickName =LoginSp.instance().getLoginIdentity().getLoginName().toString().trim();
                            }
                            if(detailedMobilePhone.toString().trim().length() == 0){
                                detailedMobilePhone = LoginSp.instance().getLoginIdentity().getLoginName().toString().trim();
                            }
                           /* Log.v("2222","detailedNickName = "+detailedNickName);
                            Log.v("2222","detailedSex = "+detailedSex);
                            Log.v("2222","detailedMobilePhone = "+detailedMobilePhone);
                            Log.v("2222","detailedEmail = "+detailedEmail);
                            Log.v("2222", "detailedHeadPortrait = " + detailedHeadPortrait);
                            Log.v("2222", "detailedHeadPortrait = " + detailedSign);*/
                            RegisterSp.instance().setDetailedInfo(detailedHeadPortrait, detailedNickName, detailedSex, detailedMobilePhone, detailedEmail, detailedSign);
                            IMRegisterManager.instance().triggerEvent(RegisterEvent.MyPage.UPDATE_MY_PAGE);//更新我的页面
                            MoGuHttpClient moGuHttpClient = new MoGuHttpClient();
                            moGuHttpClient.downloadPicture(detailedHeadPortrait);//下载图片
                            new UploadPicturesAsynchronous().execute();
                            //  Toast.makeText(context,rtjson.getString("response_desc").toString(), Toast.LENGTH_SHORT).show();
                        }else if("-1".equals(responseCode)) {
                            Toast.makeText(context,rtjson.getString("response_desc").toString(), Toast.LENGTH_SHORT).show();
                        }

                    } catch (Exception e) {
                    //    Log.v("111111111111","request = "+e.getMessage());
                        e.printStackTrace();
                    }
                }
            }
            else {

                Toast.makeText(context, newMessageInfo, Toast.LENGTH_SHORT).show();
            }
         //   mProgressDialog.dismiss();
        }
    }

    private class UploadPicturesAsynchronous extends AsyncTask<Void,Void,Void>{

        @Override
        protected Void doInBackground(Void... params) {
            try {
                final Map<String, String> param = new HashMap<String, String>();
                param.put("uid", String.valueOf(IMLoginManager.instance().getLoginId()));
                final Map<String, File> files = new HashMap<String, File>();
                String path = "/storage/emulated/0/DCIM/faceImage_tailor.jpg";
                Bitmap bm = QuanzQzBimp.revitionImageSize(path);
                String newStr = path.substring(
                        path.lastIndexOf("/") + 1,
                        path.lastIndexOf("."));
                File file1 = FileUtil.saveBitmap(bm, newStr);
                files.put("uploadfile1", file1);
                MoGuHttpClient moGuHttpClient = new MoGuHttpClient();
              //  String request = moGuHttpClient.postImg("http://192.168.10.33:8080/uploadImage/UploadAvatarServlet.do", param, files);
                 String request = moGuHttpClient.postImg("http://qz.atmart.cn:4025/uploadImage/UploadAvatarServlet.do",param, files);
                //	System.out.print(request);
             //   Log.v("111111111111", "request = " + request);
            }catch (Exception e){

            }
            return null;
        }
    }

}
